var s = "bbbbb";

var lengthOfLongestSubstring = function(s) {
    if(null == s || s.length == 0) return 0;
    var maxLength = 1;
    for(var i=0,j=2;j < s.length;j++){
        var str = s.substr(i,j - i);
        var index = str.lastIndexOf(s.charAt(j));
        // console.log("str:"+str+"   j:" + s.charAt(j))
        if(index == -1){
            maxLength = Math.max(maxLength, str.length);
        }else {
            i = index + i
            maxLength = Math.max(maxLength, str.substr(index+1).length + 1);
        }
        // console.log("index:"+index + "     maxLength:"+maxLength)
    }
    return maxLength;
};

console.log(lengthOfLongestSubstring(s));